package net.fukure.android.pecabc.service;

import net.fukure.android.pecabc.MainActivity;
import net.fukure.android.pecabc.R;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;

public class Notification {
	
	private Service service;
	private android.app.Notification notification;
	
	public Notification(Service service) {
		this.service = service;
	}
	
	void show(int id){
		
		String ticker = getResourcesString(service, R.string.notification_ticker);
	    String title = getResourcesString(service, R.string.notification_title);
	    String message = getResourcesString(service, R.string.notification_msg);
	    //int icon = android.R.drawable.ic_menu_info_details;
	    int icon = android.R.drawable.stat_sys_upload;
	    long when = System.currentTimeMillis();
	    Intent intent = new Intent(service, MainActivity.class);
	    
	    if(notification==null){
	    	notification = new android.app.Notification(icon, ticker, when);
	    }
	    PendingIntent pintent = PendingIntent.getActivity(service, 0, intent, 0);
	    notification.setLatestEventInfo(service, title, message, pintent);
	    notification.flags = android.app.Notification.FLAG_ONGOING_EVENT;// | android.app.Notification.FLAG_ONLY_ALERT_ONCE;
	    
	    service.startForeground(id, notification);
	    
	}
	
	void hide(){
		service.stopForeground(true);
	}
	
	String getResourcesString(Context context, int id){
		return context.getResources().getString(id);
	}
}
